package cn.itsource.ymcc.web.controller;

import cn.itsource.result.JSONResult;
import cn.itsource.ymcc.dto.SendSmsCodeDTO;
import cn.itsource.ymcc.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;
    @PostMapping("/sendSmsCode")//开启验证功能 @Valid
    public JSONResult sendSmsCode(@RequestBody @Valid SendSmsCodeDTO dto){
        verifyCodeService.sendSmsCode(dto);
        return JSONResult.success();//默认为true 成功

    }

    @GetMapping("/imageCode/{imageCodeKey}")//开启验证功能 @Valid
    public JSONResult imageCode(@PathVariable("imageCodeKey") String uuid){
        JSONResult<String> stringJSONResult = new JSONResult<>();

        String image = verifyCodeService.image(uuid);
        stringJSONResult.setData(image);
        return stringJSONResult;//默认为true 成功

    }
}
